<template>
  <div class="app-container" style="padding:20px" @click="onClickMain">
    <div class="body-content">
      <el-scrollbar class="scroll-content" style="width:40%;">
        <div class="scroll-content" style="border: 1px #f5f5f5 solid;margin-right:5px;">
          <el-form ref="form" :inline="true" :model="uform" :rules="rules" size="small">
            <div class="title-header">
              <span>基本信息</span>
            </div>
              <el-form-item label="姓名" prop="name" label-width="80px">
              <el-input v-model="uform.account.name" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="年龄" prop="age" label-width="80px">
              <el-input v-model.number="uform.account.age" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="性别" label-width="80px">
              <el-radio-group v-model="uform.account.sex" sclass="filter-item" style="width: 120px" disabled>
                <el-radio :label="1">男</el-radio>
                <el-radio :label="0">女</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="手机号码" prop="phone" label-width="80px">
              <el-input v-model.number="uform.account.phone" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="身份证号" prop="idCard" label-width="80px">
              <el-input v-model="uform.account.idCard" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="家庭住址" prop="address" label-width="80px">
              <el-input v-model="uform.account.address" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="出生日期" prop="birthday" label-width="80px">
              <el-date-picker
                v-model="uform.account.birthday"
                type="date"
                size="small"
                class="filter-item charges-date-picker"
                placeholder="出生日期"
                value-format="yyyy-MM-dd"
                disabled
                style="width:120px"
                >
            </el-date-picker>
            </el-form-item>
            <el-form-item label="患者来源" prop="source" label-width="80px" disabled>
                <el-select v-model="uform.account.source" class="filter-item" style="width:120px" placeholder="患者来源" disabled>
                  <el-option
                    v-for='item in accountsourceTypes'
                    :key='item.id'
                    :label='item.text'
                    :value='item.id'
                  />
                </el-select>
              </el-form-item>


            <div class="title-header">
            <span>就诊信息</span>
          </div>
            <el-col>
              <el-form-item label="接诊类型" prop="name" label-width="80px">
                <el-radio-group class="filter-item" v-model="uform.consult.consultType"  style="width:180px" disabled>
                  <template v-for="item in typeList">
                    <el-radio-button
                      :key="item.id"
                      :label="item.id"
                    >
                      {{ item.text }}
                    </el-radio-button>
                  </template>
              </el-radio-group>
              </el-form-item>
            </el-col>

              <el-form-item label="就诊科室" prop="consultDepartId" label-width="70px" disabled>
                <el-select v-model="uform.consult.consultDepartId" class="filter-item" style="width: 120px" placeholder="就诊科室" disabled>
                  <el-option
                    v-for='item in collectDepts'
                    :key='item.id'
                    :label='item.text'
                    :value='item.id'
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="接诊医生" prop="consultDocId" label-width="80px">
                <el-select v-model="uform.consult.consultDocId" class="filter-item" style="width: 120px" placeholder="接诊医生" disabled>
                  <el-option
                    v-for='item in users'
                    :key='item.id'
                    :label='item.text'
                    :value='item.id'
                  />
                </el-select>
              </el-form-item>
            <el-form-item label="诊断" prop="diagnosis" label-width="70px">
              <el-select v-model="uform.consult.diagnosis" class="filter-item" placeholder="选择诊断" multiple filterable
                         remote reserve-keyword :remote-method="remoteMethod">
                <el-option
                  v-for='item in diagnosisList'
                  :key='item.tcmDiseasesId'
                  :label='item.diseasesName'
                  :value='item.diseasesName'
                />
              </el-select>
            </el-form-item>


            <div>
            </div>

            <div class="title-header">
              <span>其他信息</span>
            </div>

            <el-form-item label="婚姻状况" prop="membershipType" label-width="80px">
              <el-select v-model="uform.account.membershipType" class="filter-item" style="width: 120px"
                         placeholder="婚姻状况" disabled>
                <el-option
                  v-for='item in maritalstatusTypes'
                :key='item.id'
                :label='item.text'
                :value='item.id'
                />
              </el-select>
            </el-form-item>
            <el-form-item label="民族" prop="nation" label-width="80px">
              <el-select v-model="uform.account.nation" class="filter-item" style="width: 120px" placeholder="请选择" disabled>
                <el-option
                v-for='item in nationTypes'
                :key='item.id'
                :label='item.text'
                :value='item.id'
                />
              </el-select>
            </el-form-item>
            <el-form-item label="慢病标志" label-width="80px">
              <el-radio-group v-model="uform.account.isChronicDisease" style="width: 120px" class="filter-item"  disabled>
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="过敏史" prop="allergicHistory" label-width="80px">
              <el-input v-model="uform.account.allergicHistory" style="width:120px" disabled/>
            </el-form-item>
            <el-form-item label="个人病史" prop="personalHistory" label-width="80px">
              <el-input v-model="uform.account.personalHistory" style="width:120px" disabled/>
            </el-form-item>


            <el-form-item label="慢性病史" prop="illness" label-width="80px">
              <el-input v-model="uform.account.illness" style="width:120px" disabled/>
            </el-form-item>
          </el-form>
        </div>
      </el-scrollbar>
      <el-scrollbar class="scroll-content" style="width:60%;margin-left:5px;">
        <div>
          <div class="tab-head">
              <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="成药处方" name="first">
                  <div style="border:2px solid #f2f2f2;padding:10px;" class="wDrug-content">
                    <div class="top-c">
                      <div class="leftc" style="width:20%;">
                        <span class="optionbtn">处方</span>
                      </div>
                      <div v-if="orderDataList1">
                        <span class="optionbtn" @click="onClickRrescription(2,orderDataList1,9999)">删除处方</span>
                      </div>
                    </div>
                    <div style="margin-top:5px">
                      <el-table ref="table" v-loading="crud.loading" :data="orderDataList1" style="width: 100%;" >
                        <el-table-column  type="index" label="序号" min-width="20"></el-table-column>
                        <el-table-column prop="drugName" label="药品名称" width="160px">
                          <template slot-scope="scope">
                            <template v-if="scope.row.flage">
                              <drugSearch
                                @select-drug="onSelectDrug"
                                ref="drugSearch1"
                                :drugType="2"
                              />
                            </template>
                            <template v-else>{{ scope.row.drugName }}</template>
                          </template>
                        </el-table-column>
                        <el-table-column v-if="columns.visible('drugSpec')" prop="drugSpec" label="规格"/>
                        <el-table-column v-if="columns.visible('dose')" prop="dose" label="单次剂量" width="140px">
                          <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-input v-model="scope.row.dose" size="small" placeholder="剂量" style="width:70px" maxlength="3" :show-word-limit='false'></el-input>
                              <span>{{scope.row.doseUnit}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column v-if="columns.visible('usageName')" prop="usageName" label="使用方法" width="120px">
                          <template slot-scope="scope" v-if="!scope.row.flage">
                            <el-select v-model="scope.row.usageName" class="filter-item" placeholder="使用方法">
                              <el-option
                                v-for='item in userMethodsList'
                                :key='item.id'
                                :label='item.name'
                                :value='item.name'
                              />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column v-if="columns.visible('frequency')" prop="frequency" label="用药频次" width="130px">
                          <template slot-scope="scope" v-if="!scope.row.flage">
                            <el-select v-model="scope.row.frequency" class="filter-item" style="width: 120px"
                                       placeholder="用药频次">
                              <el-option
                                v-for='item in frequencys'
                                :key='item.id'
                                :label='item.text'
                                :value='item.text'
                              />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column v-if="columns.visible('quantity')" prop="quantity" label="开药量" width="140px">
                          <template slot-scope="scope" v-if="!scope.row.flage">
                            <el-input v-model="scope.row.quantity" size="small" placeholder="开药量" style="width:70px" @input="onInputSingleDose(scope.row)" maxlength="10" :show-word-limit='false'></el-input>
                            <span>{{scope.row.packageUnit || scope.row.packUnit}}</span>
                          </template>
                        </el-table-column>
                        <el-table-column v-if="columns.visible('dPrice')" prop="dPrice" label="金额"/>
                        <el-table-column
                          v-permission="['admin','user:edit','user:del']"
                          label="操作"
                          width="60px"
                          align="center"
                          fixed="right"
                        >
                          <template slot-scope="scope">
                            <template v-if="!scope.row.flage">
                              <el-button
                                type="text"
                                @click="onRowHandle(scope.row,2,orderDataList1)"
                              >删除</el-button>
                            </template>
                          </template>
                        </el-table-column>
                      </el-table>
                    </div>
                  </div>
                </el-tab-pane>
                <el-tab-pane label="中药饮片处方" name="second">
                  <template v-for="(dataLists, index) in cDrugDataList1">
                    <div
                      style="border:2px solid #f2f2f2;padding:10px;"
                      class="wDrug-content"
                      :key="'second' + index"
                    >
                      <div class="top-c">
                        <div class="leftc" style="width:20%;">
                          <span class="optionbtn">处方 {{index>0?index:''}}</span>
                        </div>
                        <div v-if="dataLists">
                          <span class="optionbtn" @click="onClickRrescription(1,cDrugDataList1,index)">删除处方</span>
                        </div>
                      </div>
                      <div style="margin-top:5px">
                        <el-table ref="table" v-loading="crud.loading" :data="dataLists" style="width: 100%;" >
                          <el-table-column  type="index" label="序号" min-width="20"></el-table-column>
                          <el-table-column prop="drugName" label="药品名称" width="160px">
                            <template slot-scope="scope" >
                              <template v-if="scope.row.flage">
                              <drugSearch
                                @select-drug="onSelectDrug"
                                @focus="onTapClick(index)"
                                ref="drugSearch12"
                                :drugType="1"
                              />
                            </template>
                            <template v-else>{{ scope.row.drugName }}</template>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('drugSpec')" prop="drugSpec" label="规格" />
                          <el-table-column v-if="columns.visible('dose')" prop="dose" label="单次剂量" width="140px">
                            <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-input v-model="scope.row.dose" size="small" placeholder="剂量" style="width:70px" @input="onInputSingleqDose(scope.row,1)" maxlength="3" :show-word-limit='false'></el-input>
                              <span>{{scope.row.doseUnit}}</span>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('quantity')" prop="quantity" label="开药量" width="140px">
                            <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-input v-model="scope.row.quantity" size="small" placeholder="开药量" style="width:70px" @input="onInputSingleDose(scope.row)" disabled
                              ></el-input>
                              <span>{{scope.row.packageUnit || scope.row.packUnit}}</span>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('decoctionName')" prop="decoctionName" label="煎法" width="130px">
                            <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-select v-model="scope.row.decoctionName" class="filter-item" style="width: 120px" placeholder="煎法">
                                <el-option
                                  v-for='item in dectionName'
                                  :key='item.id'
                                  :label='item.text'
                                  :value='item.text'
                                />
                              </el-select>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('dPrice')" prop="dPrice" label="金额"/>
                          <el-table-column
                            v-permission="['admin','user:edit','user:del']"
                            label="操作"
                            width="60px"
                            align="center"
                            fixed="right"
                          >
                            <template slot-scope="scope">
                              <template v-if="!scope.row.flage">
                                <el-button
                                  type="text"
                                  @click="onRowHandle(scope.row,1,dataLists)"
                                >删除</el-button>
                              </template>
                            </template>
                          </el-table-column>
                        </el-table>
                      </div>
                      <div style="margin-top:10px">
                        <el-form :inline="true" :model="dataLists[dataLists.length - 1].drguForm">
                          <el-form-item label="总剂量">
                            <el-col :span="14">
                              <el-input @input="totalNumChange(dataLists)" v-model="dataLists[dataLists.length - 1].drguForm.num" placeholder="总剂量" size="mini" maxlength="3" :show-word-limit='false'></el-input>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="用法">
                            <el-col>
                              <el-select v-model="dataLists[dataLists.length - 1].drguForm.takeMethod"
                                         class="filter-item" style="width: 90px" placeholder="用法">
                                <el-option
                                  v-for='item in userMethodsList'
                                  :key='item.id'
                                  :label='item.name'
                                  :value='item.name'
                                />
                              </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="剂型">
                            <el-col >
                              <el-select
                                v-model="dataLists[dataLists.length - 1].drguForm.pstType"
                                class="filter-item" style="width: 120px" placeholder="剂型"
                                @focus="onTapClick(index)"
                                @change="onPstTypeChange"
                              >
                                <el-option
                                  v-for='item in cPstTypeList'
                                  :key='item.value'
                                  :label='item.label'
                                  :value='item.value'
                                />
                              </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="制作工艺">
                            <el-col >
                              <el-select v-model="dataLists[dataLists.length - 1].drguForm.dosageForm" class="filter-item" style="width: 120px" placeholder="制作工艺">
                                <el-option
                                  v-for='item in dataLists[dataLists.length - 1].ccdosageFormList'
                                  :key='item.value'
                                  :label='item.label'
                                  :value='item.value'
                                />
                            </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="用药频次">
                            <el-col >
                              <el-select v-model="dataLists[dataLists.length - 1].drguForm.frequency"
                                         class="filter-item" style="width: 120px" placeholder="用药频次">
                                <el-option
                                  v-for='item in frequencys'
                                  :key='item.id'
                                  :label='item.text'
                                  :value='item.text'
                                />
                              </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="服用要求" :inline="false">
                            <el-col >
                              <el-input style="width:30vw" v-model="dataLists[dataLists.length - 1].drguForm.useRequire" placeholder="服用要求"></el-input>
                            </el-col>
                          </el-form-item>
                        </el-form>
                      </div>
                    </div>
                  </template>
                  <div class="addPrescription" @click="onAddClick">+新增处方</div>
                </el-tab-pane>
                <el-tab-pane label="中药颗粒剂处方" name="thrid">
                  <template v-for="(dataLists, index) in cDrugDataList2">
                    <div
                      style="border:2px solid #f2f2f2;padding:10px;"
                      :key="'thrid' + index"
                      class="wDrug-content"
                    >
                      <div class="top-c">
                        <div class="leftc" style="width:20%;">
                          <span class="optionbtn">处方 {{ index > 0 ? index : '' }}</span>
                        </div>
                        <div v-if="dataLists">
                          <span class="optionbtn" @click="onClickRrescription(3,cDrugDataList2,index)">删除处方</span>
                        </div>
                      </div>
                      <div style="margin-top:5px">
                        <el-table ref="table" v-loading="crud.loading" :data="dataLists" style="width: 100%;" >
                          <el-table-column  type="index" label="序号" min-width="20"></el-table-column>
                          <el-table-column prop="drugName" label="药品名称" width="160px">
                            <template slot-scope="scope" >
                              <template v-if="scope.row.flage">
                              <drugSearch
                                @select-drug="onSelectDrug"
                                @focus="onTapClick(index)"
                                ref="drugSearch3"
                                :drugType="3"
                              />
                            </template>
                            <template v-else>{{ scope.row.drugName }}</template>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('drugSpec')" prop="drugSpec" label="规格" width="140"/>
                          <el-table-column v-if="columns.visible('dose')" prop="dose" label="单次剂量" width="140px">
                            <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-input
                                @input="onInputSingleqDose(scope.row,1)"
                                v-model="scope.row.dose"
                                :show-word-limit='false'
                                style="width:70px"
                                placeholder="剂量"
                                maxlength="3"
                                size="small"
                              />
                              <span>{{scope.row.doseUnit}}</span>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('quantity')" prop="quantity" label="开药量" width="140px">
                            <template slot-scope="scope" v-if="!scope.row.flage">
                              <el-input v-model="scope.row.quantity" size="small" placeholder="开药量" style="width:70px" @input="onInputSingleDose(scope.row)" disabled></el-input>
                              <span>{{scope.row.packageUnit || scope.row.packUnit}}</span>
                            </template>
                          </el-table-column>
                          <el-table-column v-if="columns.visible('dPrice')" prop="dPrice" label="金额"/>
                          <el-table-column
                            v-permission="['admin','user:edit','user:del']"
                            label="操作"
                            width="60px"
                            align="center"
                            fixed="right"
                          >
                            <template slot-scope="scope">
                              <template v-if="!scope.row.flage">
                                <el-button
                                  type="text"
                                  @click="onRowHandle(scope.row,3,dataLists)"
                                >删除</el-button>
                              </template>
                            </template>
                          </el-table-column>
                        </el-table>
                      </div>
                      <div style="margin-top:10px">
                        <el-form :inline="true" :model="dataLists[dataLists.length - 1].drguForm">
                          <el-form-item label="总剂量">
                            <el-col :span="14">
                              <el-input @input="totalNumChange(dataLists)" v-model="dataLists[dataLists.length - 1].drguForm.num" placeholder="总剂量" size="mini" maxlength="3" :show-word-limit='false'></el-input>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="用法">
                            <el-col>
                              <el-select v-model="dataLists[dataLists.length - 1].drguForm.takeMethod"
                                         class="filter-item" style="width: 90px" placeholder="用法">
                                <el-option
                                  v-for='item in userMethodsList'
                                  :key='item.id'
                                  :label='item.name'
                                  :value='item.name'
                                />
                              </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="用药频次">
                            <el-col >
                              <el-select v-model="dataLists[dataLists.length - 1].drguForm.frequency" class="filter-item" style="width: 120px" placeholder="用药频次">

                                <el-option
                                  v-for='item in frequencys'
                                  :key='item.id'
                                  :label='item.text'
                                  :value='item.text'
                                />
                              </el-select>
                            </el-col>
                          </el-form-item>
                          <el-form-item label="服用要求" :inline="false">
                            <el-col >
                              <el-input style="width:30vw" v-model="dataLists[dataLists.length - 1].drguForm.useRequire" placeholder="服用要求"></el-input>
                            </el-col>
                          </el-form-item>
                        </el-form>
                      </div>
                    </div>
                  </template>
                  <div class="addPrescription" @click="onAddClick">+新增处方</div>
                </el-tab-pane>

                <el-tab-pane label="历史处方" name="history">
                   <span slot="label" class="history"><i class="el-icon-date"></i> 历史处方</span>
                </el-tab-pane>
              </el-tabs>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <div class="bottom-content">
      <div>合计:</div>
      <div>{{totalFeeData()}}</div>
      <el-button
        @click="onClickBottom(0)"
        :loading="submitLoading"
        class="review-btn"
        type="primary"
      >费用预览
      </el-button>
      <el-button
        @click="onClickBottom(1)"
        :loading="submitLoading"
        type="primary"
      >完成处方
      </el-button>
    </div>
    <el-dialog
      class="clinic-operate-dialog"
      :width="dialogWidth"
      append-to-body
      top="5vh"
      title="费用预览"
      :close-on-click-modal="false"
      :visible.sync="showFeeFlage"
    >
    <div class="clinic-operate-from">
      <el-row class="pay-content">
        <span style="padding:5px;font-size:14px;">订单金额</span>
        <span style="padding:5px;font-size:14px;">{{totalFeeData()}}</span>
      </el-row>
      <el-row class="pay-content">
        <div v-for="(item,index) in infoDrugList" :key="index" style="padding:5px;">
          <el-col style="background:#F5F5F5;padding:5px;font-size:14px;" :span="4">
            <span>{{durtType(item.prescriptionType)}}</span>
          </el-col>
          <el-col style="background:#F5F5F5;padding:5px;font-size:14px;" :span="20">
            <span>药材费:</span>
            <span>{{carDrugFee(item.infoDrugs,item.prescriptionType,item.num)}}</span>
            <template v-if="(item.pstType === 1 && item.dosageForm === 2)">
              <span>加工费:</span>
              <span style="padding-left:10px">{{item.num*processCost}}</span>
            </template>
            <template v-else-if="item.pstType === 5">
              <span>加工费:</span>
              <span style="padding-left:10px">{{gfPocessCost}}</span>
            </template>
          </el-col>
        </div>
      </el-row>
    </div>
    <div slot="footer" class="dialog-footer">
        <template><el-button  type="primary" @click="showFeeFlage=false">确认</el-button>
        </template>
      </div>
    </el-dialog>
     <el-dialog
      class="clinic-operate-dialog"
      :width="dialogWidths"
      append-to-body
      top="5vh"
      title="历史处方"
      :close-on-click-modal="false"
      :visible.sync="showHistoryFlage"
      :before-close="historyBeforeClose"
    >
    <div class="clinic-operate-from">
      <hOrder ref="hOrder" :docId="this.uform.consult.consultDocId"/>
    </div>
    <div slot="footer" class="dialog-footer">
        <template><el-button  type="primary" @click="historyBeforeClose">关闭</el-button>
        </template>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  delDrug,
  delPrestion,
  detail,
  getDetails,
  getDiagnosis,
  getUseFormList,
  saveOrder
} from '@/api/outpatientService/perscription'
import {getConsultStatus, getPatientSex} from "@/utils/index";
import {getCollectUses, getDepartments} from '@/api/storageRoom/drugDelivery';
import CRUD, {form, header, presenter} from '@crud/crud';
import crudOperation from '@crud/CRUD.operation';
import udOperation from '@crud/UD.operation';
import pagination from '@crud/Pagination';
import drugSearch from "./moudle/search";
import hOrder from "./moudle/order";
import {Scrollbar} from "element-ui";
import {mapGetters} from 'vuex';

let crud = CRUD({

});

let defaultForm = {

}
export default {
  name: 'outpatientDrug',
  mixins: [presenter(crud), header(),form(defaultForm)],
  // 数据字典
  dicts: ['job_status'],
  data() {
    return {
      dOrderid:null,
      userMethodsList: [],
      infoDataList:[],
      diagnosisList:[],
      orderDataList:[{flage:true,drugName:''}],
      orderDataList1:[{flage:true,drugName:'',drguForm:{num:1}}],
      orderDataList2:[{flage:true,drugName:''}],
      orderDataList3:[{flage:true,drugName:''}],
      cDrugDataList1:[[{flage:true,drugName:'',drguForm:{num:1}}]],
      cDrugDataList2:[[{flage:true,drugName:'',drguForm:{num:1}}]],
      cPstTypeList: [
        {label:'饮片',value:1},
        // {label:'颗粒',value:2},
        // {label:'打粉',value:3},
        // {label:'制丸',value:4},
        {label:'膏方',value:5},
      ],
      cdosageFormLists:[
        [
          {label:'自煎',value:1},
          {label:'代煎',value:2}
        ],
        [
          {label:'无',value:1}
        ],
        [
          {label:'细粉',value:1},
          {label:'粗粉',value:2}
        ],
        [
          {label:'水丸',value:1},
          {label:'蜜丸',value:2},
          {label:'大蜜丸',value:3},
          {label:'浓缩丸',value:4},
          {label:'水蜜丸',value:5}
        ],
        [
          {label:'瓶装',value:1},
          {label:'袋装',value:2},
          {label:'块装',value:3}
        ],
      ],
      cdosageFormList:[],
      currentSelect1:0,
      currentSelect2:0,
      drugNames:'',
      infoDrugList: [],
      isSerach: false,
      showFeeFlage: false,
      showHistoryFlage: false,
      activeName: 'first',
      curActiveName: 'first',
      tabClickFlage: 0,
      collectDepts: [],
      restaurants: [],
      restaurantSelect: [],
      users: [],
      flagList: [
        {id: 1, text: '待就诊'},
        {id: 2, text: '就诊中'},
        {id: 3, text: '已完成'},
        {id: 4, text: '已取消'}
      ],
      typeList: [
        {id: 1, text: '初诊'},
        {id: 2, text: '复诊'},
        {id: 3, text: '急诊'}
      ],
      uform: {
        account: {
          address: "",
          age: 0,
          birthday: "",
          createTime: "",
          id: null,
          idCard: "",
          illness: "",
          isChronicDisease: 0,
          jzCount: 0,
          labelDtos: null,
          maritalStatus: "",
          member: {
            checkDiscount: 0,
            diagnosisTreatmentDiscount: 0,
            id: 0,
            inspectionDiscount: 0,
            materialCostDiscount: 0,
            memberName: "",
            otherExpensesDiscount: 0,
            pharmacyId: "",
            prescriptionOrderDiscount: 0,
            status: 0,
            treatmentOrderDiscount: 0
          },
          membershipName: "",
          membershipType: "",
          name: "",
          nation: "",
          occupation: "",
          pharmacyId: "",
          phone: "",
          remark: "",
          sex: 0,
          source: "",
          status: 0,
          totalFee: 0,
          wechat: "",
          workUnit: ""
        },
        consult: {
          allergicHistory: "",
          bloodPressureHigh: "",
          bloodPressureLow: "",
          bloodSugar: "",
          caseUrl: "",
          consultComplaint: "",
          consultDepartId: "",
          consultDepartName: "",
          consultDocId: "",
          consultDocName: "",
          consultFlag: 0,
          consultHpi: "",
          consultNo: "",
          consultStatus: 0,
          consultType: 0,
          createTime: "",
          createUserId: "",
          createUserName: "",
          criticalSigns: 0,
          diagnosis: "",
          docAdvice: "",
          familyHistory: "",
          heartRate: "",
          id: null,
          isChronicDisease: 0,
          isFood: 0,
          morbidityDate: "",
          pastHistory: "",
          patientId: "",
          patientName: "",
          personalHistory: "",
          pharmacyId: "",
          remark: "",
          temperature: "",
          updateUserId: "",
          updateUserName: "",
          weight: ""
        },
        orderDetailDto: {
          apiOrderNo: "",
          consultNo: "",
          deliveryType: 0,
          departmentId: "",
          departmentName: "",
          docId: "",
          docName: "",
          drugCost: 0,
          expressCode: "",
          expressFee: 0,
          id: null,
          infoList: [],
          diagnosis:[],
          machinFee: 0,
          orderNo: "",
          orderStatus: 0,
          orderTime: "",
          orderType: 0,
          otherCost: 0,
          patientAge: "",
          patientId: "",
          patientName: "",
          patientSex: 0,
          payStatus: 0,
          payTime: "",
          pharmacyId: "",
          prescriptionChargeList: [],
          remark: "",
          source: "",
          sourceId: "",
          sourceStoreId: "",
          sourceStoreName: "",
          totalFee: 0
        }
      },
      rules: {
        sort: [
          {required: true, message: '请输入序号', trigger: 'blur', type: 'number'}
        ],
        dept: {required: true, message: '所属部门不能为空', trigger: 'select'}
      },
      showBatchImport: false,
      showUserMsg: false,
      submitLoading: false,
    }
  },
  components: {
    crudOperation,
    pagination,
    udOperation,
    Scrollbar,
    drugSearch,
    hOrder
  },
  computed: {
    ...mapGetters([
      "workunitTypes",
      "nationTypes",
      "maritalstatusTypes",
      "accountsourceTypes",
      "processCost",
      "gfPocessCost",
      "frequencys",
      "dectionName",
      "visitedViews",
    ]),
    dialogWidth() {
      return window.innerWidth * 0.6 + "px";
    },
    dialogWidths() {
      return window.innerWidth * 0.8 + "px";
    },
  },
  activated() {
    this.loadInit();
  },
  mounted() {
    this.loadInit();
  },
  created() {
    this._getDepartments();
    this._getCollectUses();
  },
  methods: {
    getPatientSex,
    getConsultStatus,
    loadInit() {
      let userid = this.$route.query.userid;
      detail(userid).then(res => {
        this.uform = res;
        this.uform.account.membershipType = parseInt(this.uform.account.membershipType);
          this.uform.account.nation = parseInt(this.uform.account.nation);
          this.uform.account.source = parseInt(this.uform.account.source);
        if(this.uform.consult.diagnosis){
          this.uform.consult.diagnosis = this.uform.consult.diagnosis.split(',');
        }

        if(this.uform.orderDetailDto){
          this.dOrderid = this.uform.orderDetailDto.id;
          this.cDrugDataList1 = [];
          this.cDrugDataList2 = [];
          this.orderDataList1 = [{flage: true, drugName: '', drguForm: {num: 1}}];
          if(this.uform.orderDetailDto.infoList){
            this.uform.orderDetailDto.infoList.forEach(item => {
              var tNum = item.num;
              item.infoDrugs.forEach(ele => {
                ele.quantity = ele.quantity;
                ele.qNum = tNum;
                ele.payStatus = item.payStatus;
                ele.pstType = item.pstType;
                ele.dosageForm = item.dosageForm;
                ele.dPrice = parseFloat(ele.quantity*ele.price).toFixed(2);
              });
              if(item.prescriptionType == 2){
                this.orderDataList1=item.infoDrugs
                var obj =  {flage:true,drugName:'',id:null};
                this.orderDataList1.push(obj)
                this.orderDataList1.forEach(em => {
                  em.dId = item.id;
                });
              }else if(item.prescriptionType == 1){

                var tempList = item.infoDrugs;
                var tMap = {flage:true,drugName:'',drguForm:item,id:null};

                tMap.id = item.id;
                if(item.pstType){
                  tMap.ccdosageFormList = this.cdosageFormLists[item.pstType - 1];
                }
                this.cDrugDataList1.push(tempList);
                tempList.push(tMap);

              }else if(item.prescriptionType == 3){
                var tempList = item.infoDrugs;
                var tMap = {flage:true,drugName:'',drguForm:item,id:null};
                tMap.id = item.id;

                this.cDrugDataList2.push(tempList);
                tempList.push(tMap);
              }
            });
            if(this.cDrugDataList1.length < 1){
              this.cDrugDataList1 = [[{flage:true,drugName:'',drguForm:{num:1}}]];
            }
            if(this.cDrugDataList2.length < 1){
              this.cDrugDataList2 = [[{flage:true,drugName:'',drguForm:{num:1}}]];
            }
            if(this.orderDataList1.length < 1){
              this.orderDataList1 = [{flage:true,drugName:'',drguForm:{num:1}}];
            }


          }
        }
      });

      this.getUserFormDataList(1);
    },
    onDetailData(userid){

    },
    onClickUses(data){
      getDetails(data.id).then(res => {
        if(res.order) {
        if(res.order.infos){
          res.order.infos.forEach(item => {
            item.id = null;
            var tNum = item.num;
            item.infoDrugs.forEach(ele => {
              ele.id = '';
              ele.infoNo = '';
              ele.orderNo = '';
              ele.isCancel = 0;
              ele.drugSpec = ele.specification;
              ele.quantity = ele.quantity;
              ele.qNum = tNum;
              ele.payStatus = item.payStatus;
              ele.pstType = item.pstType;
              ele.dosageForm = item.dosageForm;
              ele.dPrice = parseFloat(ele.quantity*ele.price).toFixed(2);
            });
            if(item.prescriptionType == 2){
              this.orderDataList1=item.infoDrugs
              var obj =  {flage:true,drugName:'',id:null};
              this.orderDataList1.push(obj)
              this.orderDataList1.forEach(em => {
                em.dId = item.id;
              });
            }else if(item.prescriptionType == 1){

              var tempList = item.infoDrugs;
              var tMaps = {flage:true,drugName:'',drguForm:item,id:null};

              tMaps.id = item.id;
              if(item.pstType){
                tMaps.ccdosageFormList = this.cdosageFormLists[item.pstType - 1];
              }
              this.cDrugDataList1.push(tempList);
              tempList.push(tMaps);


            }else if(item.prescriptionType == 3){
              var tempList = item.infoDrugs;
              var tMap = {flage:true,drugName:'',drguForm:item,id:null};
              tMap.id = item.id;

              this.cDrugDataList2.push(tempList);
              tempList.push(tMap);
            }
          });
          if(this.cDrugDataList1.length < 1){
            this.cDrugDataList1 = [[{flage:true,drugName:'',drguForm:{num:1}}]];
          }
          if(this.cDrugDataList2.length < 1){
            this.cDrugDataList2 = [[{flage:true,drugName:'',drguForm:{num:1}}]];
          }
          if(this.orderDataList1.length < 1){
            this.orderDataList1 = [{flage:true,drugName:'',drguForm:{num:1}}];
          }


        }
        this.cDrugDataList1.reverse();
        this.cDrugDataList2.reverse();
        this.showHistoryFlage = false;
      this.curActiveName = 'first';
      this.activeName = 'first';
      }
        // this.handleData(res, openPrint);
        // this.loading = false;
      });
      // this.showHistoryFlage = false;
      // this.curActiveName = 'first';
      // this.activeName = 'first';
      // this.crud.toQuery();
      // this.$message.success('调用历史处方');
    },
    remoteMethod(query){
        getDiagnosis(query).then(res => {
          this.diagnosisList = res.content;
      });
    },
    totalNumChange(data){
      data.forEach(item => {
        item.discountPrice = item.discountPrice?item.discountPrice:item.salePrice;
        if(item.drugName) {
          let num = data[data.length - 1].drguForm.num;
          this.$set(item, "qNum", num);
        }
        if(item.dose) {
          var a = item.dose;
          item.dose = 1;
          item.dose = a;
          let quantity = Number(item.dose)*data[data.length - 1].drguForm.num;
          this.$set(item, "quantity", quantity);
        }
        if(item.drugName && item.dose) {
          let dPrice = parseFloat(item.quantity*item.salePrice).toFixed(2);
          this.$set(item, "dPrice", dPrice);
        }
      });
      this.totalFeeData();
    },
    durtType(type){
        switch (type) {
            case 1:
                return '中药处方(饮片)'
                break;
            case 2:
                return '成药处方'
                break;
            case 3:
                return '中药处方(颗粒剂) '
                break;
            case 4:
                return '输液处方'
                break;
            case 5:
                return '敷贴处方'
                break;
            default:
                break;
        }
    },
    totalFeeData(){
      var tPrice = 0.0;
      // 饮片加工费
      var pstFeeData = 0.0;
      // 膏方加工费
      let gfFeeData = 0;
      this.orderDataList1.forEach(item => {
        item.discountPrice = item.discountPrice?item.discountPrice:item.salePrice;
        if(item.quantity&&item.discountPrice){
         tPrice = tPrice + item.quantity*item.discountPrice
        }
      });

      this.cDrugDataList1.forEach(item => {
        var lastObj = item[item.length - 1];
        item.forEach(el=>{
          if(el.drugName&&el.qNum){
            if(lastObj.drguForm.pstType == 1 && lastObj.drguForm.dosageForm == 2) {
              // 饮片加工费
              pstFeeData = parseInt(el.qNum)*this.processCost;
            }
          }

          el.discountPrice = el.discountPrice?el.discountPrice:el.salePrice;
          if(el.dose&&el.discountPrice){
            tPrice = tPrice + el.dose*el.discountPrice*parseInt(el.qNum)
          }
        });
        if(lastObj.drguForm.pstType === 5) {
          // 膏方加工费
          gfFeeData += this.gfPocessCost;
        }
      });

      this.cDrugDataList2.forEach(item => {
        item.forEach(el=>{
          el.discountPrice = el.discountPrice?el.discountPrice:el.salePrice;
          if(el.dose&&el.discountPrice){
            tPrice = tPrice + el.dose*el.discountPrice*parseInt(el.qNum)
          }
        });
      });
      return parseFloat(tPrice + pstFeeData + gfFeeData).toFixed(2);
    },
    _getDepartments() {
      getDepartments().then(res => {
        res.forEach(item => {
          this.collectDepts.push({
            id: item.id + "",
            text: item.departmentName
          });
        });
      });
    },
    _getCollectUses() {
      getCollectUses().then(res => {
        res.content.forEach(item => {
          this.users.push({
            id: item.id + "",
            text: item.nickName
          });
        });
      });
    },
    onClickRrescription(type,data,index) {
      const that = this
      this.$confirm('是否确认删除该处方？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        if(type != 2){
        // 中药
        var delList = data[index];
        var map = delList[delList.length - 1];
        if(map.id){
         let deleParams = {id:map.id}
        delPrestion(deleParams).then(res => {
         if(type == 1){
            that.cDrugDataList1.splice(index,1)
          }else{
            that.cDrugDataList2.splice(index,1)
          }
      });
        }else{
          if(type == 1){
            that.cDrugDataList1.splice(index,1)
          }else{
            that.cDrugDataList2.splice(index,1)
          }

        }

      }else{
        if(data.length > 1){
          var map = data[data.length - 1];
        if(map.dId){
         let deleParams = {id:map.dId}
        delPrestion(deleParams).then(res => {
         that.orderDataList1 = [{flage:true,drugName:''}];
      });
        }else{
          that.orderDataList1 = [{flage:true,drugName:''}];

        }
        }
      }
      })
    },
    onPstTypeChange(e) {
      var tempList = this.cDrugDataList1[this.currentSelect1];
      var flage = tempList[tempList.length - 1].drguForm.dosageForm;
      if(flage){
         tempList[tempList.length - 1].drguForm.dosageForm  = ''
      }
      tempList[tempList.length - 1].ccdosageFormList = this.cdosageFormLists[e - 1];

    },
    carDrugFee(list,type,num){
      num = 1;
     var price = 0;
     num = num?num:1;
     if(type == 1||type == 3){
       list.forEach(item => {

         item.discountPrice = item.discountPrice?item.discountPrice:item.salePrice;
         if(item.quantity&&item.discountPrice){
           price = price + item.quantity*num*item.discountPrice
        }
       });
     }

     if(type == 2){
       list.forEach(item => {

         item.discountPrice = item.discountPrice?item.discountPrice:item.salePrice;
         if(item.quantity&&item.discountPrice){
         price = price + item.quantity*item.discountPrice
        }
       });
     }

      return parseFloat(price).toFixed(2)
    },
    onAddClick(){
      if(this.curActiveName == 'second'){
        this.cDrugDataList1.push([{flage:true,drugName:'',drguForm:{}}])
      }else if(this.curActiveName == 'thrid'){
        this.cDrugDataList2.push([{flage:true,drugName:'',drguForm:{}}])
      }

    },
    getUserFormDataList(type){
    var  params = {
        status: 0,
        useAllClinic:type
      }
      getUseFormList(params).then(res => {
        this.userMethodsList = res;
      });
    },
    onInputSingleqDose(item){
      item.qNum = item.qNum?item.qNum:1;
      item.quantity = item.dose*item.qNum;
      if(item.quantity > item.stock){
         this.$message.error(`${item.drugName}库存不足`)
      }

      item.dPrice = parseFloat(item.quantity*item.salePrice).toFixed(2);
      this.totalFeeData();
    },
    onInputSingleDose(item){
      if(item.quantity > item.stock){

        this.$message.error(`${item.drugName}库存不足`)
      }
      item.dPrice = parseFloat(item.quantity*item.salePrice).toFixed(2);
      this.totalFeeData();
    },
    onClickBottom(index) {
      this.submitLoading = true;
      var tcempMap = {};
      this.infoDataList = [];
      if(this.orderDataList1) {
        if(index ==1){
          tcempMap = this.orderDataList1[0];
          var lastObj = this.orderDataList1[this.orderDataList1.length - 1];
          if (lastObj != undefined && !lastObj.drugName) {
            this.orderDataList1.splice(this.orderDataList1.length - 1, 1);
          }
        }
      }
      this.cDrugDataList1.forEach(item => {
        var drugDict = {};
        var tempMap = item[item.length - 1].drguForm;
        // if(!item.drugName){
        //   tempMap.qNum = item.qNum;
        // }
        var cList = [];
        item.forEach(e => {
          if(e.drugName.length > 0) {
            if(index == 1) {
            e.quantity = e.dose;
            }
            cList.push(e);
          }
        });
        // item.splice(item.length - 1,1);
        drugDict.prescriptionType = 1;
        if(cList.length > 0){
          drugDict.infoDrugs = cList;
          drugDict.docId = this.uform.consult.consultDocId;
          drugDict.patientId = this.uform.consult.patientId;
          drugDict.dosageForm =tempMap.dosageForm;
          drugDict.frequency = tempMap.frequency;
          drugDict.num = tempMap.num;
          drugDict.id = tempMap.id?tempMap.id:'';
          drugDict.pstType = tempMap.pstType;
          drugDict.takeMethod = tempMap.takeMethod;
          drugDict.useRequire = tempMap.useRequire;
          this.infoDataList.push(drugDict);
        }
      });
      this.cDrugDataList2.forEach(item => {
        var drugDict = {};
        var tempMap = item[item.length - 1].drguForm;
        var cList = [];
        item.forEach(e => {
          if(e.drugName){
            if(index == 1){
            e.quantity = e.dose;
            }
            cList.push(e);
          }
        });
        // item.splice(item.length - 1,1);
        drugDict.prescriptionType = 3;
        if(cList.length > 0){
        drugDict.infoDrugs = cList;
          drugDict.docId = this.uform.consult.consultDocId;
          drugDict.patientId = this.uform.consult.patientId;
          drugDict.dosageForm =tempMap.dosageForm;
          drugDict.frequency = tempMap.frequency;
          drugDict.num = tempMap.num;
          drugDict.id = tempMap.id?tempMap.id:'';
          drugDict.pstType = tempMap.pstType;
          drugDict.takeMethod = tempMap.takeMethod;
          drugDict.useRequire = tempMap.useRequire;
          this.infoDataList.push(drugDict);
        }
      });

      // this.orderDataList3.splice(this.orderDataList3.length - 1,1);
      let saveForm = {};
      if(this.orderDataList1.length > 0){
        var drugDict = {};
        drugDict.num = 1;
        drugDict.prescriptionType = 2;
        drugDict.infoDrugs = this.orderDataList1;
        drugDict.docId = this.uform.consult.consultDocId;
        drugDict.patientId = this.uform.consult.patientId;
        drugDict.id = tcempMap.dId ? tcempMap.dId : '';
        this.infoDataList.push(drugDict);
      }
      if (index == 0) {
        this.infoDrugList = [];
        this.infoDrugList = this.infoDataList;
        if (this.infoDrugList && this.infoDrugList.length > 0) {
          this.showFeeFlage = true;
        }
        this.submitLoading = false;
      } else if (index === 1) {
        var diasList = this.uform.consult.diagnosis;
        if (diasList) {
          this.uform.consult.diagnosis = this.uform.consult.diagnosis.toString();
        } else {
          this.uform.consult.diagnosis = "";
        }
        saveForm.consult = this.uform.consult;
        saveForm.info = this.infoDataList;
        saveForm.orderId = this.uform.orderDetailDto ? this.uform.orderDetailDto.id : '';
        saveOrder(saveForm).then(res => {
          this.submitLoading = false;
          this.$notify({
            title: "操作成功",
            type: "success"
          });
          this._toOrderPage();
        }).catch(err => {
          console.error("............... ", err);
          this.submitLoading = false;
          var obj =  {flage:true,drugName:'',id:null};
          this.orderDataList1.push(obj)
        });
      }
    },
    onTapClick(index){
      if(this.curActiveName == 'second'){
        this.currentSelect1 = index;
      }else if(this.curActiveName == 'thrid'){
        this.currentSelect2 = index;
      }
    },
    onSelectDrug(row) {
      this.isSerach = false;
      if(this.curActiveName == 'first') {
        var obj = this.orderDataList1[this.orderDataList1.length - 1];
        obj.drugName = '';
        row.drugId = row.id;
        row.id = '';
        row.useUnit = row.packageUnit;
        var isContainerFlage =  this.isContainDrug(this.orderDataList1,row);
        if(!isContainerFlage) {
          this.orderDataList1.splice(this.orderDataList1.length - 1,0,row);
        }
      } else if(this.curActiveName == 'second') {
        var tempList = this.cDrugDataList1[this.currentSelect1];
        var obj =tempList[tempList.length - 1];
        obj.drugName = '';
        row.drugId = row.id;
        row.id = '';
        row.useUnit = row.packageUnit;
        var isContainerFlage =  this.isContainDrug(tempList,row);
        if(!isContainerFlage){
          row.qNum = obj.drguForm.num?obj.drguForm.num:1;
          tempList.splice(tempList.length - 1,0,row);
        }
      } else if(this.curActiveName == 'thrid') {
        var tempList = this.cDrugDataList2[this.currentSelect2];
        var obj =tempList[tempList.length - 1];
        obj.drugName = '';
        row.drugId = row.id;
        row.id = '';
        row.useUnit = row.packageUnit;
        var isContainerFlage =  this.isContainDrug(tempList,row);
        if(!isContainerFlage){
          row.qNum = obj.drguForm.num?obj.drguForm.num:1;
          tempList.splice(tempList.length - 1,0,row);
        }
      }
    },
    isContainDrug(list,row){
      for (let index = 0; index < list.length; index++) {
        const item = list[index];
        if(item.drugId == row.drugId){
          this.$message.error(`处方中已包含${row.drugName}`);
          return true;
        }
      }
    },
    onClickMain(){
      this.isSerach = false;
    },
    typeRadioChange(e){
      if(e == 1){
        this.getUserFormDataList(2);
      }else{
        this.getUserFormDataList(3);
      }
    },
    historyBeforeClose(){
      // this.$message.error('close');
      this.showHistoryFlage = false;
      this.curActiveName = 'first';
      this.activeName = 'first';
      this.crud.toQuery();
    },
    handleClick(tab, event) {
      //  this.infoDrugDataList(this.curActiveName);
      if(tab.name != 'history'){
        if(tab.name == 'first'){
         this.getUserFormDataList(1);
       }else if(tab.name == 'second'){
         this.getUserFormDataList(2);
       }else if(tab.name == 'thrid'){
         this.getUserFormDataList(3);
       }
       this.curActiveName = tab.name;
      }else if(tab.name == 'history'){
        this.showHistoryFlage = true;
       }


    },
    infoDrugDataList(type){
      // var drugDict = {};
      // if(type == 'first'){
      //   // drugDict.id = this.uform.orderDetailDto?this.uform.orderDetailDto.infoList[0].id:'';
      //   drugDict.prescriptionType = 2;
      //   drugDict.infoDrugs = this.orderDataList1;
      //   drugDict.docId = this.uform.consult.consultDocId;
      //   drugDict.patientId = this.uform.consult.patientId;
      //   this.infoDataList.push(drugDict);
      // }else if(type == 'second'){
      //   // pType = 1;
      //   drugDict.prescriptionType = 1;
      //    drugDict.infoDrugs = this.orderDataList2;
      //   drugDict.docId = this.uform.consult.consultDocId;
      //   drugDict.patientId = this.uform.consult.patientId;
      //   this.infoDataList.push(drugDict);
      // }else if(type == 'thrid'){
      //   // pType = 1;
      //   drugDict.prescriptionType = 3;
      //    drugDict.infoDrugs = this.orderDataList2;
      //   drugDict.docId = this.uform.consult.consultDocId;
      //   drugDict.patientId = this.uform.consult.patientId;
      //   this.infoDataList.push(drugDict);
      // }


    },
    onClickTab(index){
        this.tabClickFlage = index;
    },
    onOperateRow(id,operate) {
        this.uform = operate;
    },
    onRowHandle(data,type,list) {
      const that = this
      this.$confirm('是否确认删除该药品？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        if(type != 2){
        // 中药
        // var delList = data[index];
        var map = data;//delList[delList.length - 1];

          if(map.infoNo){
         let deleParams = {id:map.id}
        delDrug(deleParams).then(res => {
         if(type == 1){
           var index = list.indexOf(data);
            list.splice(index,1)
          }else{
            var index = list.indexOf(data);
            list.splice(index,1)
          }
      });
        }else{
          if(type == 1){
            var index = list.indexOf(data);
            list.splice(index,1)
          }else{
            var index = list.indexOf(data);
            list.splice(index,1)
          }

        }

      }else{
        // if(list.length > 1){
          var map = data;
        if(map.infoNo){
         let deleParams = {id:map.id}
        delDrug(deleParams).then(res => {
          var index = list.indexOf(data);
          list.splice(index,1)
        //  that.orderDataList1 = [{flage:true,drugName:''}];
      });
        }else{
           var index = list.indexOf(data);
          list.splice(index,1)


        }
        if(that.orderDataList1.length < 1){
          that.orderDataList1 = [{flage:true,drugName:''}];
        }
        // }
      }
      })
    //  let index = this.orderDataList.indexOf(data);
    //  this.orderDataList.splice(index,1);
    },
    [CRUD.HOOK.dataLoadSuccess](crud, data) {

    },
    [CRUD.HOOK.afterRefresh]() {

    },
    _operateBtns(item) {
      let res = [];


      return res;
    },
    onBatchImportSuccess() {
      this.showBatchImport=false;
      this.crud.toQuery();
      this.searchCountByDrugType();
    },
    onBatchImport(e) {


    },
    // 关闭当前页，前往订单页
    _toOrderPage() {
      let selectView = null;
      for(let view of this.visitedViews) {
        if(view.name === this.$route.name) {
          selectView = view;
        }
      }
      if(selectView) {
        this.$store.dispatch('tagsView/delView', selectView).then(() => {
          this.$router.replace({ path: "../../ordermag/outorder", query: { tab: "2" } });
        });
      } else {
        this.$router.replace({ path: "../../ordermag/outorder", query: { tab: "2" } });
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
/deep/ .el-input-number .el-input__inner {
  text-align: left;
}
.tab-head{
  margin-top: 0px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.history{
  z-index: 9999;
  text-align: right;
  // padding-left: 300px;
}
.body-content{
  display: flex;
  flex-direction: row;
}
.title-header{
  color: #333;
  padding: 10px;
  font-size: 18px;
  font-weight: 500px;
  border-top: 1px #f5f5f5 solid;

}
.addPrescription{
  text-align: right;
  color: cornflowerblue;
  font-size: 15px;
  margin: 10px 0 10px 0;
  padding-right: 10px;
}
.optionbtn{
  padding-left: 10px;
  color: cornflowerblue;
  font-size: 15px;
  cursor:pointer;
}
.left-content{
  height: 100%;
  border:1px solid #f2f2f2;
}
.tab{
  background-color:#f2f2f2;
    height:44px;
    display: flex;
    flex-direction: row;
}
.tab-content-sel{
    background-color:#65AF79;
    width:120px;
    height:44px;
    color:#ffffff;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    font-size: 15px;
}
.tab-content{
    width:120px;
    height:44px;
    color:#333333;
    display: flex;
    flex-direction: row;
    justify-content: center;

    align-items: center;
    font-size: 15px;
}
.scroll-content{
  height: calc(100vh - 200px);

  /deep/ .el-scrollbar__wrap {
    overflow-x: hidden;
  }
}
.bottom-content{
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  font-size: 15px;
  height: 60px;
  margin-top: 15px;
  border-top: 1px solid #f2f2f2;

  .review-btn {
    margin-left: 10px;
  }
}
.wDrug-content{
  .top-c{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    color: #65AF79;
    .leftc{
      display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding-left: 10px;
    font-size: 13px;
    }
  }
}
.info-popover-table {
  overflow-y: auto;
  max-height: 200px;
}
</style>
